package com.ruoyi.cluster.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cluster.domain.KwClusterNodeInfo;
import com.ruoyi.cluster.service.IKwClusterNodeInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基础信息——节点列Controller
 * 
 * @author gonianer
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/cluster/node")
public class KwClusterNodeInfoController extends BaseController
{
    @Autowired
    private IKwClusterNodeInfoService kwClusterNodeInfoService;

    /**
     * 查询基础信息——节点列列表
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(KwClusterNodeInfo kwClusterNodeInfo)
    {
        startPage();
        List<KwClusterNodeInfo> list = kwClusterNodeInfoService.selectKwClusterNodeInfoList(kwClusterNodeInfo);
        return getDataTable(list);
    }

    /**
     * 导出基础信息——节点列列表
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:export')")
    @Log(title = "基础信息——节点列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KwClusterNodeInfo kwClusterNodeInfo)
    {
        List<KwClusterNodeInfo> list = kwClusterNodeInfoService.selectKwClusterNodeInfoList(kwClusterNodeInfo);
        ExcelUtil<KwClusterNodeInfo> util = new ExcelUtil<KwClusterNodeInfo>(KwClusterNodeInfo.class);
        util.exportExcel(response, list, "基础信息——节点列数据");
    }

    /**
     * 获取基础信息——节点列详细信息
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(kwClusterNodeInfoService.selectKwClusterNodeInfoById(id));
    }

    /**
     * 新增基础信息——节点列
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:add')")
    @Log(title = "基础信息——节点列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KwClusterNodeInfo kwClusterNodeInfo)
    {
        return toAjax(kwClusterNodeInfoService.insertKwClusterNodeInfo(kwClusterNodeInfo));
    }

    /**
     * 修改基础信息——节点列
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:edit')")
    @Log(title = "基础信息——节点列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KwClusterNodeInfo kwClusterNodeInfo)
    {
        return toAjax(kwClusterNodeInfoService.updateKwClusterNodeInfo(kwClusterNodeInfo));
    }

    /**
     * 删除基础信息——节点列
     */
    @PreAuthorize("@ss.hasPermi('cluster:node:remove')")
    @Log(title = "基础信息——节点列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(kwClusterNodeInfoService.deleteKwClusterNodeInfoByIds(ids));
    }
}
